home *** CD-ROM | disk | FTP | other *** search
/ Mac Power 1997 December / MACPOWER-1997-12.ISO.7z / MACPOWER-1997-12.ISO / AMUG / PROGRAMMING / Raven 1.2.sit / Raven 1.2 / Source / Foundation / Common / ZBestFitAllocator.h < prev    next >
Text File  |  1997-06-17  |  2KB  |  79 lines

  1. /*
  2.  *  File:       ZBestFitAllocator.h
  3.  *  Summary:    An allocator that uses the ODMemMgr from MacApp.
  4.  *  Written by: Jesse Jones
  5.  *
  6.  *    Abstract:    This allocator is about as fast as TSimpleAllocator but does
  7.  *                a much better job giving memory back to the OS. However if your
  8.  *                app makes heavy use of doubles you may want to use TSimpleAllocator
  9.  *                since BestFitHeap only aligns blocks to 4-byte boundaries.
  10.  *
  11.  *  Copyright ゥ 1997 Jesse Jones. 
  12.  *    For conditions of distribution and use, see copyright notice in ZTypes.h  
  13.  *
  14.  *  Change History (most recent first):
  15.  *
  16.  *         <->     1/30/97    JDJ        Created
  17.  */
  18.  
  19. #pragma once
  20.  
  21. #include <MemMgr.h>
  22. #include <ZAllocator.h>
  23.  
  24.  
  25. //-----------------------------------
  26. //    Forward References
  27. //
  28. class BestFitHeap;
  29.  
  30.  
  31. // ===================================================================================
  32. //    class TBestFitAllocator
  33. // ===================================================================================
  34. class TBestFitAllocator : public TAllocator {
  35.  
  36.     typedef TAllocator Inherited;
  37.  
  38. //-----------------------------------
  39. //    Initialization/Destruction
  40. //
  41. public:
  42.     virtual                ~TBestFitAllocator();
  43.  
  44.                         TBestFitAllocator(ulong initialSize, ulong poolSize, ulong hugeSize = 0,
  45.                                           MMHeapLocation heap = kMMAppMemory);
  46.                         // Heap will start with initialSize bytes. When the heap is 
  47.                         // exhausted a new pool with poolSize bytes will be allocated.
  48.                         // Blocks larger than hugeSize are always allocated using NewPtr 
  49.                         // and never reused (0 means poolSize/4).
  50.                         
  51. //-----------------------------------
  52. //    Inherited API
  53. //
  54. public:
  55.     virtual    void*        Allocate(ulong bytes);
  56.                         
  57.     virtual    void         Deallocate(void* block);
  58.  
  59.     virtual ulong         GetHeapSize() const;
  60.             
  61.     virtual ulong         GetPoolCount() const;
  62.                         
  63.     virtual ulong         GetBlockSize(const void* ptr) const;
  64.  
  65.     virtual    ulong         GetTotalBlockSize(const void* ptr) const;
  66.  
  67. #if DEBUG
  68.     virtual void         ValidateBlock(const void* ptr) const;
  69.             
  70.     virtual void         ValidateHeap(BlockValidateHook hook = nil, void* refCon = nil) const;
  71. #endif
  72.  
  73. //-----------------------------------
  74. //    Member Data
  75. //
  76. protected:    
  77.     BestFitHeap*    mHeap;
  78. };
  79.